<tc_include file="Portal/Public/style" />
    <title>登录</title>
<tc_include file="Portal/Public/header" />
<!--header end-->
<div class="login_top">
    <form action="{:U('Register/doLogin')}" method="post">
    <div class="login_center">
        <div class="llogo tc pb10"><img src="__IMG__/dlogo.png" width="147" height="54" alt=""/></div>
        <div class="tips none">输入错误，请重试</div>
        <div class="inpout"><input type="text" id="tel" name="tel" required placeholder="输入手机号"/></div>
        <div class="inpout"><input type="password" id="pass" name="pass" required placeholder="输入密码"/></div>
        <div class="wjmm tr"><a href="{:U('Register/forget')}">忘记密码</a></div>
        <div class="btn"><input id="login" type="button" value="登录"/></div>
        <div class="reg"><span>没有账号？</span><a href="{:U('Register/register')}">注册</a></div>
        <div class="stit">第三方账号登陆</div>
        <div class="sanf">
            <a href="javascript:;"><img src="__IMG__/swx.png" alt=""/></a>
            <a href="javascript:;"><img src="__IMG__/sqq.png" alt=""/></a>
        </div>
    </div>
    </form>
</div>
<tc_include file="Portal/Public/footer" />
<script>
    $("#tel").blur(function(){
        var val = $(this).val();
        if(val == ""){
            $(".tips").hide();
        }else{
            var reg = /^1[34578]\d{9}$/;
            var isTrue = reg.test(val);
            if(!isTrue){
                $(".tips").text("手机号格式不正确").show();
            }else{
                $(".tips").hide();
            }
        }
    });
    $("#pass").blur(function(){
        var val = $(this).val();
        if(val == ""){
            $(".tips").hide();
        }else{
            var reg = /^[\w1-9_]{3,9}$/;
            var isTrue = reg.test(val);
            if(!isTrue){
                $(".tips").text("密码格式不正确").show();
            }else{
                $(".tips").hide();
            }
        }
    });
    //实现不跳转登录
    $("#login").click(function(){
        var tel = $("#tel").val();
        var pass = $("#pass").val();
        if(tel && pass && $('.tips').is(':hidden')){
            $.ajax({
                url:"{:U('Register/doLogin')}",
                type:"post",
                async:true,
                data:{
                    "tel":tel,
                    "pass":pass
                },
                //dataType:"json", 如果返回的不是json时，不要设置
                success:function(data){
                    console.log(data);
                    if(data == 1){
                        var con = confirm("登录成功！跳转首页。");
                        if(con){
                            //点击确认则跳转首页
                            location.href = "{:U('Index/index')}";
                        }else{
                            //点击取消则取消

                        }
                    }else if(data == 2){
                        var con = confirm("登录失败,账号密码不符。");
                        if(con){
                            //点击确认则跳转首页
                        }else{
                            //点击取消则取消

                        }
                    }
                }
            })
        }

    });
</script>
</body>
</html>